import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/login/Login.vue'
import Home from "../views/Home";
//import Menu from "../views/system/Menu";

const routes = [
  {
    path: "/",
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
    redirect: '/home/index',
        children: [
          {
            path: '/home/index',
            name: 'index',
            component:   () => import('../views/login/Index'),
            meta: {
              title: '首页'
            },
          },
          {
            path: '/home/mytext',
            name: 'mytext',
            component: () => import('../views/my/myText'),
            meta:{
              title: '数据报表'
            },
          },
          {
                path: '/system/user',
                name: 'User',
                component:  () => import('../views/system/User'),
                meta:{
                  title: '用户管理'
                },
          },
          {
            path: '/system/menu',
            name: 'Menu',
            component:   () => import('../views/system/Menu'),
            meta:{
              title: '菜单管理'
            },
          },
          {
            path: '/system/roles',
            name: 'Roles',
            component:  () => import('../views/system/roles/Roles'),
            meta:{
              title: '角色管理'
            },

              },
          {
            path: '/system/controller',
            name: 'Controller',
            component: () => import('../views/system/Controller'),
            meta:{
              title: '数据字典'
            },

          },
          {
            path: '/system/jurisdiction',
            name: 'Jurisdiction',
            component: () => import('../views/system/jurisdiction'),
            meta:{
              title: '资源权限'
            },
          },
          {
            path: '/my/add',
            name: 'Add',
            component: () => import('../views/my/Add'),
            meta:{
              title: '添加'
            },
          },
            ]
      }


]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next();
  } else {
    let _token = sessionStorage.getItem('token');
    if (!_token) {
      return  next('/login');
    } else {
      next();
    }
  }
});
export default router
